/*
 * @Author: C.
 * @Date: 2023-01-29 14:20:11
 */
import { BasicColumn } from '/@/components/Table/src/types/table';
import { fieldsToMaps } from './index';
import { MoreProps } from '../../utils/help/createFields';
import { useI18n } from '/@/hooks/web/useI18n';
import { RelationLink } from '../../utils/help/erphelp';
import { stateEnum } from '/@/maps/index';
const { t } = useI18n();
// todo: 值类型可以花时间改成动态推导
export type tableFieldType =
  | 'CustomerId'
  | 'Tax'
  | 'Currency'
  | 'BillId'
  | 'BillGui'
  | 'CustomerName'
  | 'DeliveryDate'
  | 'State'
  | 'Creator'
  | 'CreationDate'
  | 'Remarks'
  | 'Id'
  | 'ItemId'
  | 'ItemName'
  | 'Description'
  | 'Unit'
  | 'Quantity'
  | 'Price'
  | 'Amount'
  | 'Stockroom'
  | 'AssociatedNo'
  | 'LotNumber'
  | 'SupplierId'
  | 'Submitter'
  | 'Department'
  | 'SupplierName'
  | 'TDA'
  | 'SalesReps'
  | 'PhotoUrl'
  | 'ItemType'
  | 'BomId'
  | 'NoTaxPrice'
  | 'AuxiliaryQty'
  | 'AuxiliaryPrice'
  | 'RelationId'
  | 'StockroomLocation';
// type Keys = typeof tableFields[number]['dataIndex'];
export const tableFields: (BasicColumn & MoreProps)[] = [
  { dataIndex: 'CustomerId', title: t('commonField.CustomerId'), sorter: true },
  { dataIndex: 'Tax', title: t('commonField.Tax'), defaultValue: 0, width: 60 },
  { dataIndex: 'Currency', title: t('commonField.Currency'), filter: 'tag', width: 60 },
  {
    dataIndex: 'BillId',
    title: t('commonField.BillId'),
    filter: 'link',
    width: 180,
    resizable: true,
    fixed: 'left',
    sorter: true,
  },
  { dataIndex: 'BillGui', title: t('commonField.BillGui'), sorter: true },
  { dataIndex: 'CustomerName', title: t('commonField.CustomerName') },
  { dataIndex: 'DeliveryDate', title: t('commonField.DeliveryDate'), filter: 'date' },
  {
    dataIndex: 'State',
    title: t('commonField.State'),
    filter: 'state',
    sorter: true,
    // filterMultiple: false,
    filters: stateEnum.getEnums().map((item) => {
      return {
        text: item.label,
        value: item.value,
      };
    }),
  },
  { dataIndex: 'Creator', title: t('commonField.Creator'), sorter: true },
  { dataIndex: 'CreationDate', title: t('commonField.CreationTime'), filter: 'time', sorter: true },
  { dataIndex: 'Remarks', title: t('commonField.Remarks') },
  { dataIndex: 'Id', title: t('commonField.Id') },
  {
    dataIndex: 'ItemId',
    title: t('commonField.ItemId'),
    filter: 'link',
    width: 180,
    fixed: 'left',
    resizable: true,
    componentProps: {
      routerName: 'Ba_Item_Detail',
      // 效果如{Id:record.cId}
      routeKeyValue: [['Id', 'ItemId']],
      // routerMethod 默认 query
    },
  },
  { dataIndex: 'ItemName', title: t('commonField.ItemName') },
  { dataIndex: 'Description', title: t('commonField.Description') },
  { dataIndex: 'Unit', title: t('commonField.Unit'), filter: 'tag', width: 60 },
  {
    dataIndex: 'Quantity',
    title: t('commonField.Quantity'),
    defaultValue: 1,
    width: 100,
    sorter: (a: Recordable, b: Recordable) => Number(a.Quantity) - Number(b.Quantity),
  },
  {
    dataIndex: 'Price',
    title: t('commonField.Price'),
    filter: 'amount',
    defaultValue: 0,
    width: 100,
    sorter: (a: Recordable, b: Recordable) => Number(a.Price) - Number(b.Price),
  },
  {
    dataIndex: 'Amount',
    title: t('commonField.Amount'),
    filter: 'amount',
    defaultValue: 0,
    align: 'right',
    sorter: (a: Recordable, b: Recordable) => Number(a.Amount) - Number(b.Amount),
  },
  { dataIndex: 'Stockroom', title: t('commonField.Stockroom') },
  { dataIndex: 'AssociatedNo', title: t('commonField.AssociatedNo') },
  { dataIndex: 'LotNumber', title: t('commonField.LotNumber'), width: 100 },
  { dataIndex: 'SupplierId', title: t('commonField.SupplierId') },
  { dataIndex: 'Submitter', title: t('commonField.Submitter') },
  { dataIndex: 'Department', title: t('commonField.Department') },
  { dataIndex: 'SupplierName', title: t('commonField.SupplierName') },
  {
    dataIndex: 'TDA',
    title: t('commonField.TDA'),
    filter: 'amount',
    defaultValue: 0,
    align: 'right',
    sorter: (a: Recordable, b: Recordable) => Number(a.TDA) - Number(b.TDA),
  },
  { dataIndex: 'SalesReps', title: '销售员' },
  {
    dataIndex: 'PhotoUrl',
    title: '图片',
    filter: 'image',
    width: 80,
    componentProps: { circled: true },
  },
  { dataIndex: 'ItemType', title: '标签', filter: 'tag' },
  {
    dataIndex: 'BomId',
    title: '物料清单',
    filter: 'link',
    componentProps: {
      routerName: 'Ba_Bom_Detail',
      // 效果如{Id:record.cId}
      routeKeyValue: [['Id', 'BomId']],
      // routerMethod 默认 query
    },
  },
  {
    dataIndex: 'NoTaxPrice',
    title: '未税单价',
    width: 100,
    sorter: (a: Recordable, b: Recordable) => Number(a.NoTaxPrice) - Number(b.NoTaxPrice),
  },
  {
    dataIndex: 'AssociatedNo',
    title: '关联单号',
    customRender: ({ value }) => {
      return RelationLink({ target: value });
    },
  },
  // RelationId
  {
    dataIndex: 'RelationId',
    title: '相关单号',
  },
  {
    dataIndex: 'AuxiliaryQty',
    title: '辅助数量',
    width: 100,
    sorter: (a: Recordable, b: Recordable) => Number(a.AuxiliaryQty) - Number(b.AuxiliaryQty),
  },
  {
    dataIndex: 'AuxiliaryPrice',
    title: '辅助单价',
    width: 100,
    sorter: (a: Recordable, b: Recordable) => Number(a.AuxiliaryPrice) - Number(b.AuxiliaryPrice),
  },
  {
    dataIndex: 'StockroomLocation',
    title: t('commonField.StockroomLocation'),
    width: 100,
  },
];

export default fieldsToMaps<BasicColumn>(tableFields, 'dataIndex');
